define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feedback/index' + location.search,
                   /* add_url: 'washlog/add',
                    edit_url: 'washlog/edit',
                    del_url: 'washlog/del',
                    multi_url: 'washlog/multi',
                    import_url: 'washlog/import',*/
                    table: 'feedback',
                }
            });

            var table = $("#table");

            /*table.on('load-success.bs.table', function (e, data) {
                $('label[for="member_id"]').parent().css('display','none');
                $('label[for="merchant_id"]').parent().css('display','none');
            });*/
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                /*fixedColumns: true,
                fixedRightNumber: 1,*/
                visible: false,
                showToggle: false,
                showColumns: false,
                search: false,
                showExport: false,
                escape: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'member.nickname', title: __('Member.nickname'), operate: 'LIKE'},
                        {field: 'score', title: __('Score'), operate: false},
                        {field: 'evaluate', title: __('Evaluate'), operate: false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {
                            field: 'handle_data',
                            title: __('Handle_data'),
                            searchList: {"0": __('Handle_data 0'), "1": __('Handle_data 1')},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'evaluate_time', title: __('Evaluate_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons:[
                                {
                                    name: 'ok',
                                    title: '处理',
                                    text: '处理',
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: '',
                                    confirm: '确定已处理完该反馈吗？',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.handle_data == 1) {
                                            return false
                                        }
                                        return true;

                                    },
                                    url: function (row, column) {
                                        var url = 'feedback/ok?id=' + row.id + '&handle_data=1';
                                        return url;
                                    },
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh', {});
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        table.bootstrapTable('refresh', {});
                                        return false;
                                    },
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
